function init(){
	var page = 1;
	var rows = 10;
	
	$(".select-box ul").on('click','li',function(){
	    $(this).parent().siblings('.show').val($(this).html());
	    $(this).parent().siblings('.hidden').val($(this).attr('data-id'));
	});
	
	$(".select-box div.fl").click(function(e){
	    console.log('ss');
	    e.stopPropagation();
	    var div=$(this);
	    div.children('ul').toggleClass('hide');
	    $(document).click(function() {
	        if (!div.children('ul').hasClass("hide")) {
	            div.children('ul').addClass("hide");
	        }
	    });
	});
	
	/**
	 * 订单号查询的方法
	 */
	$('.search-box').on('click','span',function(){
		var conditions = findSearchConditions();
		loadComment(page, rows, conditions[0], conditions[1], conditions[2], conditions[3]);
	});
	
	/**
	 * 仓库查询的方法
	 */
	$('#warehouseSearchBox').on('click','li',function(){
		var conditions = findSearchConditions();
		loadComment(page, rows, conditions[0], conditions[1], conditions[2], conditions[3]);
	});
	
	/**
	 * 发货时间查询的方法
	 */
	$('#datePicker').on('change',function(e){
		var conditions = findSearchConditions();
		loadComment(page, rows, conditions[0], conditions[1], conditions[2], conditions[3]);
	});
	
	/**
	 * 查看的方法
	 */
	$('.data-tbody').on('click','.detail',function(e){
		var orderId = $(this).attr('data-id');
		window.location.href = path + "/distributor/orderDetail?id="+orderId;
	});
	
	//w调用日期选择插件
	$('#datePicker').daterangepicker();
	loadSearchBox();
	loadComment(page, rows, '', '', '', '');
}

/**
 * 获取所有的查询条件
 */
function findSearchConditions(){
	var strs = new Array();
	strs[0] = $('#orderId').val();
	strs[1] = $('#warehouseId').val();
	var deliveryDate = $('#datePicker').val();
	var deliveryDates = deliveryDate.split(' - ');
	strs[2] = deliveryDates[0];
	strs[3] = deliveryDates[1];
	return strs;
}

/**
 * 加载选择搜索框数据
 * @param page
 * @param rows
 */
function loadSearchBox() {
	/*
	 * 仓库选择框赋值
	 */
	$.ajax({
		type: "post",
		url: '/diconet/warehouse/warehouse/list/all',
		dataType: 'json',
		success: function(data){
			var commentContent = '<li>请选择</li>';
			if(data) {
				console.log(data);
				for(var i=0; i<data.length; i++) {
					var comment = data[i];
					var date1 = comment.publishDate == null ? '' : comment.publishDate;
					commentContent += '<li data-id="'+comment.id+'">' + comment.warehouseName+'</li>';
				}
				$('#warehouseSearchBox').html(commentContent);
			}
		},
		error : function(data){
			layer.msg('仓库搜索条件加载失败', {time:500,icon:5});
		}
	});
}

/**
 * 加载列表数据
 * @param page
 * @param rows
 */
function loadComment(page, rows, orderCode, warehouseId, beginTime, endTime) {
	$.ajax({
		type: "post",
		url: '/diconet/outbound/list/page',
		data: {
			page : page,
			rows : rows,
			orderCode : orderCode,
			warehouseId : warehouseId,
			beginTime : beginTime,
			endTime : endTime
		},
		dataType: 'json',
		success: function(data){
			var commentContent = '';
			console.log(data);
			if(data) {
				for(var i=0; i<data.rows.length; i++) {
					var comment = data.rows[i];
					var date1=comment.publishDate == null?'':comment.publishDate;
					commentContent += '<tr>';
					commentContent += '<td class="t1">'+comment.cancelReason+'</td>';// 出库单号
					commentContent += '<td class="t1">'+comment.distributorId+'</td>';// 仓库
					commentContent += '<td class="t1">'+comment.orderTime+'</td>';// 出库时间
					commentContent += '<td class="t1">'+comment.orderCode+'</td>';// 订单编号
					commentContent += '<td class="t1">'+comment.amount+'</td>';// 订单金额
					commentContent += '<td class="t1">'+comment.userId+'</td>';// 客户
					if(comment.orderState == 0)
						commentContent += '<td>处理中</td>';// 订单状态
					else
						commentContent += '<td>已关闭</td>';// 订单状态
					commentContent += '<td><button data-id="'+comment.remark+'" class="detail">查看</button></td>';
					commentContent += '</tr>';
				}
				$('.data-tbody').html(commentContent);
				var dataPage = data.page;
				var pageContent="";
				if(dataPage.firstPage) {
					pageContent += '<span class="disabled">首页</span>';
					pageContent += '<span class="disabled">上一页</span>';
				} else {
					pageContent += '<a href="javascript:loadComment('+dataPage.first+','+rows+',\''+orderId+'\',\''+warehouseId+'\',\''+beginTime+'\',\''+endTime+'\');">首页</a>';
					pageContent += '<a href="javascript:loadComment('+dataPage.prev+','+rows+',\''+orderId+'\',\''+warehouseId+'\',\''+beginTime+'\',\''+endTime+'\');">上一页</a>';
				}
				var maxPage = dataPage.page+2 < dataPage.last?dataPage.page+2:dataPage.last;
				if(dataPage.page >= 4 && dataPage.page + 2 < dataPage.last){
					for(var i=dataPage.page-2; i<= maxPage; i++) {
						if(i == dataPage.page) {
							pageContent += '<span class="current">'+i+'</span>';
						} else {
							pageContent += '<a href="javascript:loadComment('+i+','+rows+',\''+orderId+'\',\''+warehouseId+'\',\''+beginTime+'\',\''+endTime+'\');">'+i+'</a>';
						}
					}
				}else if(dataPage.page > 4 && dataPage.page + 2 >= dataPage.last){
					for(var i=dataPage.last-4; i<=dataPage.last; i++) {
						if(i == dataPage.page) {
							pageContent += '<span class="current">'+i+'</span>';
						} else {
							pageContent += '<a href="javascript:loadComment('+i+','+rows+',\''+orderId+'\',\''+warehouseId+'\',\''+beginTime+'\',\''+endTime+'\');">'+i+'</a>';
						}
					}
				}else if(dataPage.last < 5){
					for(var i=dataPage.first; i<=dataPage.last; i++) {
						if(i == dataPage.page) {
							pageContent += '<span class="current">'+i+'</span>';
						} else {
							pageContent += '<a href="javascript:loadComment('+i+','+rows+',\''+orderId+'\',\''+warehouseId+'\',\''+beginTime+'\',\''+endTime+'\');">'+i+'</a>';
						}
					}
				}else{
					for(var i=dataPage.first; i<=5; i++) {
						if(i == dataPage.page) {
							pageContent += '<span class="current">'+i+'</span>';
						} else {
							pageContent += '<a href="javascript:loadComment('+i+','+rows+',\''+orderId+'\',\''+warehouseId+'\',\''+beginTime+'\',\''+endTime+'\');">'+i+'</a>';
						}
					}
				}
				if(dataPage.lastPage) {
					pageContent += '<span class="disabled">下一页</span>';
					pageContent += '<span class="disabled">尾页</span>';
				} else {
					pageContent += '<a href="javascript:loadComment('+dataPage.next+','+rows+',\''+orderId+'\',\''+warehouseId+'\',\''+beginTime+'\',\''+endTime+'\');">下一页</a>';
					pageContent += '<a href="javascript:loadComment('+dataPage.last+','+rows+',\''+orderId+'\',\''+warehouseId+'\',\''+beginTime+'\',\''+endTime+'\');">尾页</a>';
				}
			}
			$(".quotes").html(pageContent);
		},
		error : function(data){
			layer.msg('请求失败', {time:500,icon:5}); 
		}
	});
}

init();